﻿#pragma once
#include "KeyboardHandler.h"
#include "ServiceHandle.h"

#include <tchar.h>
#include <windows.h>

#define SERVICE_NAME _T("HookF3")

class ServiceManager {
public:
  explicit ServiceManager(const TCHAR *serviceName);
  BOOL InstallService();
  BOOL UninstallService();

private:
  const TCHAR *m_serviceName;
  SC_HANDLE OpenServiceManager();
};

class Service {
public:
  static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
  explicit Service(const TCHAR *serviceName);
  void Run();

private:
  static DWORD WINAPI Handler(DWORD control, DWORD eventType, LPVOID pEventData,
                              LPVOID pContext);
  void ReportStatus(DWORD state);

  SERVICE_STATUS m_status;
  SERVICE_STATUS_HANDLE m_statusHandle;
  KeyboardHandler m_keyboardHandler;
  const TCHAR *m_serviceName;
  HANDLE m_hStopEvent; // 新增停止事件句柄
};